import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import VideoPlayer from 'vue-video-player'
require('video.js/dist/video-js.css')
require('vue-video-player/src/custom-theme.css')
Vue.use(VideoPlayer)

Vue.use(ElementUI);

// import global from './global'
// Vue.use(global)

import login_form from "@/components/login_form";
Vue.component(login_form.name,login_form)

Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

router.beforeResolve((to, from, next) => {
  const token = store.state.token;
  // 判断路由是否设置相应校验用户权限
  if (to.meta.requireLogin) {
    if (!token) {
      // 没有登录，显示登录组件
      store.state.toLogin=true;
      // this.$store.dispatch("setToLogin", true);
      if (from.name == null) {
        //此时，是在页面没有加载，直接在地址栏输入链接，进入需要登录验证的页面
        next("/");
        return;
      }
      // 终止导航
      next(false);
      return;
    }
  }
  next();
});